/**
 * @(#) ReqMedicalMoneyMediator.as
 *
 * @date		2011. 03. 28.
 * @version		1.0
 * @author		Baek, kwang hyoun
 * @description	의료비 신청 - Mediator
 * 				의료비를 신청하는 Presentation Logic을 관리
 */
package com.skt.common_hr.medicalmoney_sac.view
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.approval.RequestApprovalMediator;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.puremvc.CommonMediator;
	import com.skt.common_hr.common.utilSilver.textSilver;
	import com.skt.common_hr.medicalmoney_sac.MedicalMoneyFacade;
	import com.skt.common_hr.medicalmoney_sac.events.MedicalMoneyEvent;
	import com.skt.common_hr.medicalmoney_sac.model.*;
	import com.skt.common_hr.medicalmoney_sac.model.vo.MedicalMoneyVO;
	import com.skt.common_hr.medicalmoney_sac.model.vo.MedicalMoneyWriteVO;
	import com.skt.common_hr.medicalmoney_sac.model.vo.MedicalSubTabVO;
	import com.skt.common_hr.medicalmoney_sac.view.components.ReqMedicalMoneyViewSac;
	import com.wcl.utils.DateUtil;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class ReqMedicalMoneyMediator extends CommonMediator
	{
		public static const NAME:String = "MidicalMoneyWriteMediator";

		public static const CLOSED_REQUEST_VIEW:String	= "closedRequestView";
 		private var bWaitingApproval:Boolean = false;
 		private var bWaitingExistData:Boolean = false;
		private var _currentKey:String = "";


		/**
		* 생성자
		*
		* @param
		* @return void
		*/
        public function ReqMedicalMoneyMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }

		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		override protected function initializeView():void
 		{
 			setEventListeners();
 		}

 		private function setEventListeners():void
 		{
 			// 신청창에서 리스트창으로
 			view.addEventListener(ReqMedicalMoneyViewSac.MedicalWriteClose, goMainList);
 			view.addEventListener(MedicalMoneyFacade.SAVE_MEDICALMONEY_REQUEST, onSaveRequest);
 			view.addEventListener(MedicalMoneyFacade.LOAD_MM_CHG_YEAR_CB, onChgCbLoadMedicalMoneyLimitData);

 			view.addEventListener(MedicalMoneyFacade.APPROVAL_REQUEST, onApprovalRequest);



/* 			view.addEventListener(ReqCelebrationView.CongStandard, displaySupportStandard);
			view.addEventListener(ReqCelebrationView.CongCpernrChange, onClickSelectMember);
			view.addEventListener(ReqCelebrationView.CongAccount, onCongAccount);
			view.addEventListener(ReqCelebrationView.CongFamilySelect, onClickChangeFamily);

			//view.addEventListener(ComboBoxEvent.SELECT_DATA, onChangedCode);
			view.addEventListener(ReqCelebrationView.CHANGED_CELEBRRATION_CODE, onChangedCelebrationCode);

			//view.addEventListener(CongMoneyWriteEvent.UPDATE_DATA, onCongMoneyWriteUpdate);
			view.addEventListener(ReqCelebrationView.CongClose, onCongClose);

			// 경조일 선택시
			view.addEventListener(ReqCelebrationView.CongDaySelect, onCongDaySelect);

			// 경조휴가 가능일
			view.addEventListener(ReqCelebrationView.CongDayVocationCheck, onCongDayVocationCheck); */
 		}

 		private function removeEventListener():void
 		{
 			// 신청창에서 리스트창으로
 			view.removeEventListener(ReqMedicalMoneyViewSac.MedicalWriteClose, goMainList);
 			view.removeEventListener(MedicalMoneyFacade.SAVE_MEDICALMONEY_REQUEST, onSaveRequest);
 			view.removeEventListener(MedicalMoneyFacade.LOAD_MM_CHG_YEAR_CB, onChgCbLoadMedicalMoneyLimitData);
 			view.removeEventListener(MedicalMoneyFacade.APPROVAL_REQUEST, onApprovalRequest);
 		}


 		/**
		 * 입력으로 돌아가기
		 * @param
		 * @return void
		 */
 		private function goMainList(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
 		}

 		override protected function clearView():void
 		{
 			trace("clear WriteMediator");
 			//view.dataProvider = null;
 			//view._medicalData = null;
 			//view.current_medical = null;
 		}





		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		*
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array
		{
			return [
					MedicalMoneyFacade.LOAD_MEDICALMONEY_BANKA_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_WRITE_INITIAL,
					MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_COMPLETE,
					MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_FAILED,
					MedicalMoneyFacade.SAVE_MEDICALMONEY_COMPLETE,
					MedicalMoneyFacade.SAVE_MEDICALMONEY_FAILED,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_FAILED,
					RequestApprovalMediator.APPROVAL_CANCEL,
					RequestApprovalMediator.APPROVAL_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_FAILED
					/*

					CelebrationFacade.LOAD_CONGMONEY_WRITE_COMPLETE,
					CelebrationFacade.SAVE_CELEBRATION_COMPLETE,
					CelebrationFacade.SAVE_CELEBRATION_FAILED,

					CelebrationFacade.LOAD_FAMILY_INFO,
					CelebrationFacade.LOAD_CELEBRATION_CODE_COMPLETE,
					CelebrationFacade.LOAD_CELEBRATION_CODE_FAILED,

					CelebrationFacade.LOAD_CONGMONEY_BANKA_FAILED,
					CelebrationFacade.LOAD_FAMILY_COMPLETE,
					CelebrationFacade.LOAD_FAMILY_FAILED,
					CelebrationFacade.LOAD_CONGMONEY_SELECTED_COMPLETE,
					CelebrationFacade.LOAD_CONGMONEY_SAVE_FAILED,
					CelebrationFacade.LOAD_DEFAULT_FAMILY_FAILED,
					CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_COMPLETE,
					CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_FAILED,
					CelebrationFacade.SELECTED_FAMILY,
					CelebrationFacade.MODIFIED_ACCOUNT,
					MemberSelectorMediator.SELECTED_MEMBER,


					CelebrationCodeProxy.LOAD_CONGDAYVALIDATE_COMPLETE,
					CelebrationCodeProxy.LOAD_CONGDAYVALIDATE_FAILED,
					CelebrationCodeProxy.LOAD_CONGDAY_VOCATION_CHECK_COMPLETE,
					CelebrationCodeProxy.LOAD_CONGDAY_VOCATION_CHECK_FAILED,
					*/
					//CelebrationFacade.LOAD_CONGMONEY_WRITE_INITCEHCK
					];
		}


		/**
		* Noti별로 처리한다.
		*
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName())
			{
				// 초기 로딩시..
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_WRITE_INITIAL:
					bActivated = true;
					view.dataProvider.WSTATUS = "";
					view.currentState = "stateView";
					// 수정모드라면 입력폼 활성화.
					var t:Object = note.getBody();
					view.sReqSpmon = t.spmon;
					if(t.write == true) {
						view.bWrite = true;
					} else {
						view.bWrite = false;
					}

					loadInitialData(note.getBody().pernr, note.getBody().name, note.getBody().gwarekey);
					break;
				// 계좌정보
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_BANKA_COMPLETE:
					setBankList(note.getBody() as AccountProxy);
					break;

				case MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_COMPLETE:
					LitmitDateSetting(note.getBody() as ReqMedicalMoneyWriteProxy);
					break;
				case MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_FAILED:
					trace("MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_FAILED");
					break;
				case MedicalMoneyFacade.SAVE_MEDICALMONEY_COMPLETE:
					// 승인요청하여 결재창이 뜨도록.
					if(bWaitingApproval) {
						_currentKey = MedicalMoneyProxy(note.getBody()).key;
						view.dataProvider.GWAREKEY = parseInt(_currentKey);
						execApproval(_currentKey);

						completeMedicalMoney(note.getBody());
					}
					else {
						completeMedicalMoney(note.getBody());
						facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					}
					if(view.sAlertInfo != '') {
						CommonAlert.showMessage(commonFacade.bundle, view.sAlertInfo, null);	
					}
					
					
					bWaitingApproval = false;
					break;

				case MedicalMoneyFacade.SAVE_MEDICALMONEY_FAILED:
					bWaitingApproval = false;
					CommonAlert.showMessage(commonFacade.bundle, MedicalMoneyProxy(note.getBody()).faultMessage, null);
					break;

				case MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_COMPLETE:
					if(bActivated) {
						setLoadedDetailInfo( MedicalMoneyProxy(note.getBody()) );
					}
					break;

				case MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_FAILED:
					trace("LoadCongmoneyWriteFailed");
					break;

				// 결재 요청  성공
				case RequestApprovalMediator.APPROVAL_COMPLETE:
					bActivated = false;
		 			clearView();
		 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					//facade.sendNotification(TrainingFacade.SUCCEED_REQ_TRAINING, this);
					break;

				// 결재 요청 취소
				case RequestApprovalMediator.APPROVAL_CANCEL:
					bActivated = true;
		 			//clearView();
		 			//facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					//cancelApproval(_currentKey);
					break;


				case MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_COMPLETE:
					setMedSubjectCode(medicalSubjectCodeProxy(note.getBody()).acMedSubject, medicalSubjectCodeProxy(note.getBody()).acMedSubject2); 
					break;
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_FAILED:
					commonFacade.setStatusMessage("진료과목 조회중 오류가 발생했습니다.");
					break;
					
				/*
				case CelebrationFacade.SAVE_CELEBRATION_COMPLETE:
					//setStatusMessage("저장되었습니다.");
					if(bWaitingApproval) {
						_currentKey = CelebrationProxy(note.getBody()).key;
						view.dataProvider.GWAREKEY = _currentKey;
						execApproval(_currentKey);
					}
					else {
			 			clearView();
 						bActivated = false;
			 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
			 		}
			 		bWaitingApproval = false;
					trace("saved completed");
					break;

				case CelebrationFacade.LOAD_FAMILY_COMPLETE:
					setFamilyList(FamilyProxy(note.getBody()).family);
					break;
				case CelebrationFacade.LOAD_FAMILY_FAILED:
					//setStatusMessage("가족정보를 조회중 오류가 발생했습니다.");
					break;

				case CelebrationFacade.LOAD_CONGMONEY_BANKA_FAILED:
					trace("LoadCongmoneyBankaFailed");
					//AlertHelper.showMessage((note.getBody() as CongMoneyWriteProxy).bnksaFaultMessage);
					break;

				case CelebrationFacade.SELECTED_FAMILY:
					onFamilyDataLoad(note.getBody() as CongFamilyVO);
					break;
				case MemberSelectorMediator.SELECTED_MEMBER:
					if(bActivated) {
						onMemberDataLoad(MemberSelectorMediator(note.getBody()).selectedMember);
					}
					break;

				case CelebrationFacade.MODIFIED_ACCOUNT:
					//기타계좌 수정시 계좌관리  로드
 					//bankaLoadData();
 					//loadBankInfo(view.dataProvider.CPERNR);
 					var subMedi:CongMoneyAccountMediator = facade.retrieveMediator(CongMoneyAccountMediator.NAME) as CongMoneyAccountMediator;
 					view.dataProvider.BANKL = subMedi.BANKL;
					view.dataProvider.BANKA = subMedi.BANKA;
 					view.dataProvider.BANKN = subMedi.BANKN;
 					view.dataProvider.EMFTX = subMedi.EMFTX;
 					var index:int = ArrayHelper.indexOf(view.accounts, "BNKSA", 2);
					if(index>0) {
						var selectedAccount:CongMoneyAccountVO = view.accounts[index];
						selectedAccount.BANKL = subMedi.BANKL;
						selectedAccount.BANKA = subMedi.BANKA;
						selectedAccount.BANKN = subMedi.BANKN;
						selectedAccount.EMFTX = subMedi.EMFTX;
					}
					trace(view.dataProvider.BANKA, view.dataProvider.BANKN,view.dataProvider.EMFTX );
					break;

				case CelebrationFacade.LOAD_CONGMONEY_SELECTED_COMPLETE:
					onSelected(note.getBody() as CelebrationProxy);
					break;
				case CelebrationFacade.LOAD_CONGMONEY_SAVE_FAILED:
					//경조신청 저장시 휴가중복일경우
					onSaveErroryMessage(note.getBody() as CongMoneyWriteProxy);
					break;

				case CelebrationFacade.LOAD_DEFAULT_FAMILY_FAILED:
					trace("LoadDefaultFamilyFailed");
					CommonAlert.showMessage(commonFacade.bundle, (note.getBody() as FamilyProxy).defaultResultMessage);
					break;
				case CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_COMPLETE:
					//onCorsnMoney(note.getBody() as CongMoneyWriteProxy);
					break;
				case CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_FAILED:
					CommonAlert.showMessage(commonFacade.bundle, (note.getBody() as CongMoneyWriteProxy).corsnMoneyResultMessage);
					view.BETRG.text = "0";
 					view.ZWRTH.selectedValue = "";
					break;

				case CelebrationFacade.LOAD_CONGMONEY_WRITE_INITCEHCK:
					//대상자 변경 가능 유무 및 기간 셋팅.
					onInitCheck(note.getBody());
					break;

				case CelebrationCodeProxy.LOAD_CONGDAYVALIDATE_COMPLETE:
					onCongDaySelectHandler(note.getBody());
					break;

				case CelebrationCodeProxy.LOAD_CONGDAY_VOCATION_CHECK_COMPLETE:
					onCongDayVocationCheckHandler(note.getBody());
					break;
						 */
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}

		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 조회상세보기
		 * @param
		 * @return void
		 */
 		private function setLoadedDetailInfo(voWrapObj:MedicalMoneyProxy):void
 		{
 			var vo:MedicalMoneyVO = voWrapObj.detailVO;
 			_currentKey = vo.GWAREKEY.toString();

			view.dataProvider = vo;
			view.medicalData = voWrapObj.subTabList;

			var sTargetDate:String = vo.SPMON;


	 		loadBankInfo(Variables.myPernr);
 			loadMedicalMoneyLimitData(Variables.myPernr, sTargetDate, vo.GWAREKEY.toString() );	//의료비 마감일자와 의료비 지원가능금액 산출
 		}

		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 계좌선택 콤보 load된 데이터를 화면에 출력
		 * @param
		 * @return void
		 */
 		private function setBankList(proxy:AccountProxy):void
 		{
 			view.accounts = proxy.AccountList;

 			if(bWaitingExistData) {

 			}
 			else {
 				//view.clearAccountInfo();
 			}
 			bWaitingExistData = false;
 		}

		/**
		 * MedicalMoney 저장 완료한 후 호출됨
		 *
		 * @param
		 * @return void
		 */


 		private function completeMedicalMoney(val:Object):void
 		{
 			_currentKey = val.key;


 			//AlertHelper.showMessage("임시저장이 완료되었습니다.");

/*
 			if(view.sSaveGubun == "X") {
 				//AlertHelper.showMessage("승인요청이 완료되었습니다.");
 				facade.sendNotification(ReqMedicalMoneyMediator.CLOSED_REQUEST_VIEW, this);

 			} else {
 				AlertHelper.showMessage("임시저장이 완료되었습니다.");
 			}
 */
 		}


		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 * 마감일과 가용금액셋팅
		 * @param
		 * @return void
		 */
 		private function LitmitDateSetting(proxy:ReqMedicalMoneyWriteProxy):void
 		{
 			//view.accounts = proxy.mmLimitDateLoadList;
 			// 왜 setter를 썼을지..모르겠음. 난 그냥 함수로 씀.
 			view.LitmitDateSetting(proxy.mmLimitDateLoadList);

 			if(bWaitingExistData) {

 			}
 			else {
 				//view.clearAccountInfo();
 			}
 			bWaitingExistData = false;
 		}


		private function findCodeIndex(key:String, srcArr:ArrayCollection):int
		{
			for(var i:int=0; i<srcArr.length; i++) {
				if(srcArr[i].data == key) {
					return i;
				}
			}
			return -1;
		}
		
		//최초
		private function loadInitialData(pernr:String, name:String, gwarekey:String=""):void
		{
			view._medicalData = new ArrayCollection();
			_currentKey = ""; // 현재 키 초기화

			
 			loadCodes();							//진료과목 코드
 						
 			if(gwarekey!="") {
 				trace("modify data: " + gwarekey);
 				loadExistData(gwarekey);				//의료비 신청(입력,업데이트) 				
 			}
 			else { 				
 				view.writeDefaultSetting();

		 		loadBankInfo(Variables.myPernr);
 				loadMedicalMoneyLimitData(Variables.myPernr, null, "" );	//의료비 마감일자와 의료비 지원가능금액 산출

 			}
		}

 		private function getDefaultData():MedicalMoneyWriteVO
 		{
 			var dp:MedicalMoneyWriteVO = new MedicalMoneyWriteVO;
 			dp.IPERNR = dp.CPERNR = Variables.myPernr;
 			dp.INAME = dp.CNAME = Variables.myName;
 			dp.CODAT = DateUtil.todayNoTime();
 			dp.IDATE = DateUtil.todayNoTime();
 			dp.COSEL = "X";
 			dp.WAERS = "KRW";

 			return dp;
 		}


		private function onChgCbLoadMedicalMoneyLimitData(e:Event):void {
			var sYear:String = view.lbApplyDateYear.text;
			var sMonth:String = view.lbApplyDateMonth.text;

			loadMedicalMoneyLimitData(Variables.myPernr, sYear+sMonth,_currentKey);	//의료비 마감일자와 의료비 지원가능금액 산출
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Access Functions....
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////

		private function execApproval(key:String):void
		{
 			var approval:RequestApprovalMediator = facade.retrieveMediator(RequestApprovalMediator.NAME) as RequestApprovalMediator;
 			if(approval==null) {
 				approval = new RequestApprovalMediator(view, "11");
 				facade.registerMediator(approval);
 			}
 			bActivated = false;
 			var appProxy:MedicalMoneyApprovalProxy = facade.retrieveProxy(MedicalMoneyApprovalProxy.NAME) as MedicalMoneyApprovalProxy;
 			appProxy.key = key;
 			appProxy.dataProvider = tmpVO;
 			approval.execRequest(view, appProxy);
		}



 		private function loadExistData(gwarekey:String):void
 		{
			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
			bWaitingExistData = true;
			proxy.loadDetail(gwarekey);
 		}

 		/**
		 * 의료비 마감일자, 한도 조회
		 * @param
		 * @return void
		 */
 		private function loadMedicalMoneyLimitData(pernr:String, tagetDate:String=null, gwarekey:String=""):void
 		{
			var proxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			
			var spMon:String = view.lbApplyDateYear.text+view.lbApplyDateMonth.text;
			//var spMon:String = view.sReqSpmon;
			proxy.loadMmLimitData(pernr, tagetDate, gwarekey, spMon);
 		}

 		/**
		 * 진료과목 조회
		 * @param
		 * @return void
		*/
 		private function loadCodes(oneself:Boolean = true):void
 		{
			var proxy:medicalSubjectCodeProxy = facade.retrieveProxy(medicalSubjectCodeProxy.NAME) as medicalSubjectCodeProxy;
			proxy.loadMedSubjectCodes();
 		}
 		 

 		/**
		 * 계좌선택 콤보
		 * @param
		 * @return void
		* */
 		private function loadBankInfo(pernr:String):void
 		{
			var accountProxy:AccountProxy = facade.retrieveProxy(AccountProxy.NAME) as AccountProxy;
			accountProxy.loadAccounts(pernr);
 		}

 		/**
		 * 진료과목 셋팅
		 * @param
		 * @return void
		*/
 		private function setMedSubjectCode(list:ArrayCollection, list2:ArrayCollection):void
 		{
 			view.medSubjectCodeList = list;
 			view.medSubjectCodeList2 = list2;
 		}


		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////

 		/**
		 * 경조사 지원기준
		 * @param
		 * @return void

 		private function displaySupportStandard(event:Event):void
 		{
 			var proxy:SupportStandardProxy = facade.retrieveProxy(SupportStandardProxy.NAME) as SupportStandardProxy;

 			var congStandardView:IFlexDisplayObject = PopUpManager.createPopUp(view, SupportStandard, true);
 			PopUpManager.centerPopUp(congStandardView);
 			(congStandardView as SupportStandard).setFocus();
 			SupportStandard(congStandardView).standardList = proxy.standardList;
 		}
 		 */
 		// 임시저장
 		private function onSaveRequest(event:Event):void
 		{
 			bWaitingApproval = false;
			commonSave();
 		}

 		// 승인 요청
		private var tmpVO:MedicalMoneyVO;
 		private function onApprovalRequest(event:MedicalMoneyEvent):void
 		{
 			bWaitingApproval = true;
 			//tmpVO = view.dataProvider;
 			tmpVO = event.writeVo;

 			commonSave();
 		}

 		private function commonSave():void {
 			if(view.selectedAccount==null) {
 				Alert.show( "계좌정보가 없습니다. [인사/급여 > 급여/복리후생계좌]메뉴에서 계좌생성 후 의료비 신청하시기 바랍니다.");
 				return;
 			}
	 		// import
			var I_GWAREKEY:String 	= _currentKey;
			var I_REQUEST:String	= "";



			// table
			//ITAB
			var tItabArr:Array = new Array();
			var oItab:Object = new Object;
			oItab.GWAREKEY	= I_GWAREKEY;
			oItab.PERNR		= Variables.myPernr;
			oItab.ENAME		= Variables.myName;

			oItab.SPMON		= view.lbApplyDateYear.text + view.lbApplyDateMonth.text;
			oItab.HOWMANY	= view.totalCnt;
			oItab.HOWMUCH	= textSilver.moneyTextToInt(view.lbApplyMoney.text)/100;

			//oItab.WSTATUS // 결재 진행상태
			//oItab.WSTATX	//결재진행상태 텍스트
			
			if(view.selectedAccount!=null) {
				oItab.BANKS	= view.selectedAccount.BANKS;
				oItab.BANKL	= view.selectedAccount.BANKL;
				oItab.BANKA	= view.selectedAccount.BANKA;
				oItab.BNKSA	= view.selectedAccount.BNKSA;
				oItab.BANKN	= view.selectedAccount.BANKN;
				oItab.EMFTX	= view.selectedAccount.EMFTX;				
			} 

			oItab.STEXT	= "";

			oItab.WSTATUS= view.dataProvider.WSTATUS;

			tItabArr.push(oItab);  


			// SUB_TAB
 			var tSub_tabArr:Array = new Array();
	 		for each(var rec:MedicalSubTabVO in view.medicalData)
	 		{
	 			var data:Object = new Object;
	 			data.USEDT = DateUtil.toBasicString(rec.USEDT);
	 			data.HOSPD = rec.HOSPD;
	 			data.BETRG = rec.BETRG/100;
	 			data.MEDCD = rec.MEDCD;
	 			data.MEDTX = rec.MEDTX;
	 			data.MGBN = rec.MGBN;
	 			data.MGBT = rec.MGBT;

	 			tSub_tabArr.push(data);
	 		}

 			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
 			proxy.save(I_GWAREKEY, I_REQUEST, tItabArr, tSub_tabArr);
 		}

 		/**
		 * 경조사 저장수정
		 * @param
		 * @return void
		 */
		 /*
 		private function onCongMoneyWriteUpdate(event:CongMoneyWriteEvent):void
 		{
 			//facade.removeMediator(CongMoneyWriteMediator.NAME);
 			var proxy:CongMoneyWriteProxy = facade.retrieveProxy(CongMoneyWriteProxy.NAME) as CongMoneyWriteProxy;
 			proxy.update(event.Fkey, event.writeVo);
 		}
 		 */
 		/**
		 * 경조사 입력팝업닫기
		 * @param
		 * @return void
		 */
 		private function onCongClose(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
 		}

 		 //의료비 상세보기 조회
 		private function onSelected(proxy:MedicalMoneyProxy):void
 		{
 			var congProxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			congProxy.load(proxy.key);

 			//corsnLoadData();
 			//bankaLoadData();
 		}

 		//저장에러 메세지 휴가중복메세지
 		private function onSaveErroryMessage(proxy:ReqMedicalMoneyWriteProxy):void
 		{
 			//AlertHelper.showMessage(proxy.saveErroryMessage);
 		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():ReqMedicalMoneyViewSac
        {
            return viewComponent as ReqMedicalMoneyViewSac;
        }


	}
}